﻿using System;
using System.Data;


public static class Project
{
    #region Protected Fields
    static string projectName;
    static ProjectLanguages programminglanguage;
    static string connectionString;
    static string projectNamespace;
    static string assemblyName;
    static string projectDirectory;

    
	
    #endregion

    #region Public Properties

    public static string ProjectDirectory
    {
        get { return projectDirectory; }
        set { projectDirectory = value; }
    }
    public static string AssemblyName
    {
        get { return assemblyName; }
        set { assemblyName = value; }
    }
    public static string ProjectNamespace
    {
        get { return projectNamespace; }
        set { projectNamespace = value; }
    }

    public static string ConnectionString
    {
        get { return connectionString; }
        set { connectionString = value; }
    }

    public static ProjectLanguages ProgrammingLanguage
    {
        get { return programminglanguage; }
        set { programminglanguage = value; }
    }

    public static string ProjectName
    {
        get { return projectName; }
        set { projectName = value; }
    }
    #endregion

    public static void SaveProject()
    {
        AvvaMobileNHibernateHelperKit.Gateway.ProjectData dsProjectData = new AvvaMobileNHibernateHelperKit.Gateway.ProjectData();
        AvvaMobileNHibernateHelperKit.Gateway.ProjectData.dtProjectDataTable dtProject = new AvvaMobileNHibernateHelperKit.Gateway.ProjectData.dtProjectDataTable();
        AvvaMobileNHibernateHelperKit.Gateway.ProjectData.dtProjectRow drProjectRow = dtProject.NewdtProjectRow();
        drProjectRow.ProjectName = projectName;
        drProjectRow.ProgrammingLanguage = (int)programminglanguage;
        drProjectRow.ProjectNamespace = projectNamespace;
        drProjectRow.ConnectionString = connectionString;
        drProjectRow.AssemblyName = assemblyName;

        dtProject.AdddtProjectRow(drProjectRow);
        dsProjectData.Tables.Add(dtProject);
        dsProjectData.WriteXml(projectDirectory + @"\" + projectName + @".slnx");
    }

    public static void LoadProject(string xmlPath)
    {
        AvvaMobileNHibernateHelperKit.Gateway.ProjectData dsProjectData = new AvvaMobileNHibernateHelperKit.Gateway.ProjectData();
        dsProjectData.ReadXml(xmlPath);

        if (dsProjectData.dtProject.Rows.Count == 1)
        {
            projectName = dsProjectData.dtProject[0].ProjectName;
            programminglanguage = (ProjectLanguages)dsProjectData.dtProject[0].ProgrammingLanguage;
            projectNamespace = dsProjectData.dtProject[0].ProjectNamespace;
            connectionString = dsProjectData.dtProject[0].ConnectionString;
            assemblyName = dsProjectData.dtProject[0].AssemblyName;
        }
        else
        {
            throw new Exception("Project file could not read.");
        }
    }
}

